<?php /* @var $this Controller */ ?>
<!DOCTYPE html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

    <!-- blueprint CSS framework -->
    <link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/themes/fly_high/assets/css/screen.css" media="screen, projection" />
    <link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/themes/fly_high/assets/css/print.css" media="print" />
    <link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/themes/fly_high/assets/css/home.css"/>
    <!--[if lt IE 8]>
    <link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/themes/fly_high/assets/css/ie.css" media="screen, projection" />
    <![endif]-->

    <link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/themes/fly_high/assets/css/main.css" />
    <link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/themes/fly_high/assets/css/form.css" />
    <script type="text/javascript" src="<?php echo Yii::app()->request->baseUrl; ?>/themes/fly_high/assets/js/jquery-1.11.0.min.js"></script>
    <script type="text/javascript" src="<?php echo Yii::app()->request->baseUrl; ?>/themes/fly_high/assets/js/jquery.form.js"></script>

    <title><?php echo CHtml::encode($this->pageTitle); ?></title>
    <link rel="icon" href="<?php echo Yii::app()->request->baseUrl; ?>/themes/fly_high/assets/img/favicon.ico"/>

    <script>
    $(document).ready(function()
    {
        $( "#formLogin" ).submit(function( event )
        {
            event.preventDefault();

            $('#loading').fadeIn();
            $('#btnLogin').attr("disabled", true);

            var data     = $("#formLogin").serialize();

            var url          = "<?php echo Yii::app()->request->baseUrl; ?>/Authenticate/";

            $.ajax({
               type: 'POST',
               url: url,
               data:data,
                success:function(data){
                    $('#loading').fadeOut();
                    $('#btnLogin').attr("disabled", false);
                    console.log(data);
                    if(data == 'Đăng nhập thành công'){
                        window.location.href = "<?php Yii::app()->user->returnUrl?>";
                    }
                    else
                    {
                        alert(data);
                        if(data == 'Không có tài khoản này')
                        {
                            $("#loginEmail").val('');
                            $("#loginEmail").select();
                        }
                        else
                        {
                            $("#loginPassword").val('');
                            $("#loginPassword").select();
                        }
                    }
                },
               error: function(data) {
                    $('#loading').fadeOut();
                    $('#btnLogin').attr("disabled", false);
                   alert("Đăng nhập thất bại, vui lòng kiểm tra lại kết nối.");
            },
                dataType:'html'
            });
        });
    });
    </script>
    <title><?php echo CHtml::encode($this->pageTitle); ?></title>
</head>
<body>
<div class="container" id="page">
    <header id="header">
        <div id="loginBanner">
            <img src="<?php echo Yii::app()->request->baseUrl; ?>/themes/fly_high/assets/img/logoBanner.png" alt="logo" />
        </div>
        <fieldset>
            <form method="post" action="<?php echo Yii::app()->request->baseUrl; ?>/Authenticate/" id="formLogin">
                <div id="loginForm">
                    <table>
                        <tr>
                            <td>Email :</td>
                            <td>Mật khẩu :</td>
                            <td></td>
                        </tr>
                        <tr>
                            <td><input type="email" class="input" name="LoginForm[email]" required id="loginEmail" value="hoanglnn@fpt.edu.vn" /></td>
                            <td><input type="password" class="input" name="LoginForm[password]" required id="loginPassword" value="123456" /></td>
                            <td><input type="submit" value="Đăng nhập" name="loginAct" class="submit input" id="btnLogin"></td>
                        </tr>
                        <tr>
                            <td><input type="checkbox" name="LoginForm[rememberMe]" value="1">Duy trì đăng nhập</td>
                            <td><a href="<?php echo Yii::app()->request->baseUrl; ?>/Page/Lostpassword" style="color: #aeaeae;text-decoration: none">Không thể đăng nhập?</a></td>
                            <td></td>
                        </tr>
                    </table>
                </div>
            </form>
        </fieldset>
    </header><!-- header -->
    <section>
        <article id="content">
            <?php echo $content; ?>
        </article>
    </section>
    <?php $this->beginContent('//common/footer');$this->endContent();?>
</div><!-- page -->
</body>
</html>